package cn.hehuoren.quartz.config;

import cn.hehuoren.quartz.SpringBeanJobFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;

import javax.annotation.Resource;
import javax.sql.DataSource;

/**
 * @author Ray
 * @date 2018/3/7.
 */
@Configuration
public class QuartzConfig {
    @Resource
    private DataSource dataSource;

    @Bean
    public SchedulerFactoryBean schedulerFactoryBean(){
        SchedulerFactoryBean bean = new SchedulerFactoryBean();
        bean.setDataSource(dataSource);
        bean.setConfigLocation(new ClassPathResource("quartz.properties"));
        bean.setJobFactory(springBeanJobFactory());
        bean.setStartupDelay(30);
        return bean;
    }

    @Bean
    public SpringBeanJobFactory springBeanJobFactory(){
        return new SpringBeanJobFactory();
    }
}
